package yuejian_07.yuejian_07.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.adapter.MasterQuestionAdapter;
import yuejian_07.yuejian_07.base.RetrofitListener;
import yuejian_07.yuejian_07.javabean.Question;
import yuejian_07.yuejian_07.model.MasterModel;

public class MasterQuesFragment extends Fragment implements RetrofitListener<List<Question>> {

    private RecyclerView recyclerView;
    private List mDataList;

    private View view=null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view= inflater.inflate(R.layout.master_ques_fragment, container, false);

        initViews();
        getQalist();
        return view;
    }

    private void initViews(){

        recyclerView= (RecyclerView)view.findViewById(R.id.rv_masterquestion);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    void getQalist(){
        Bundle bundle = getActivity().getIntent().getExtras();
        int master_id = bundle.getInt("master_id");
        System.out.printf("master_id");
        MasterModel masterModel=new MasterModel();
        masterModel.Qalist(master_id,this);
    }

    @Override
    public void onSuccess(List<Question> data ){

        //System.out.printf("data");
        recyclerView.setAdapter(new MasterQuestionAdapter(MasterQuesFragment.this.getActivity(),data));
    }

    @Override
    public void onFail(){ Toast.makeText(getActivity(), "网络发生错误", Toast.LENGTH_SHORT).show();}
}
